package yl.hs.bmipfull.controllers.salemanage;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.pojo.salemanage.SaleContractAdditionalMoneyEntity;
import yl.hs.bmipfull.service.salemanage.ISaleContractAdditionalMoneyService;
import yl.hs.bmipfull.service.system.IDataDictService;
import yl.hs.bmipfull.viewmodels.WebResult;
import yl.hs.bmipfull.viewmodels.salemanmage.SaleContractAdditionalMoneyModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作用:   <br/>
 * 创建时间: 2023-02-14 13:38 <br/>
 * @author 吴高丰
 */
@Api(value = "合同技术参数费用web接口", tags = "销售管理——合同技术参数费用web接口")
@RequestMapping(value = "/api/salecontractadditionalmoney")
@RestController
public class SaleContractAdditionalMoneyController extends ControllerBase {
    @Autowired
    ISaleContractAdditionalMoneyService additionalMoneyservice;
    @Autowired
    IDataDictService dtSvc;
    @ApiOperation(value = "保存更新合同技术参数", notes = "保存更新合同技术参数")
    @RequestMapping(value = "", method = RequestMethod.POST)
    public WebResult Save(@RequestBody SaleContractAdditionalMoneyModel data){
        try {
            if(data.getData()==null){
                additionalMoneyservice.deleteByContractSn(data.getContractSn());
                return  success("更改成功");
            }else{
          var result =  additionalMoneyservice.updateSaleContractAdditional(data.getContractSn(),data.getData());
          return  success("更改成功");}
        } catch (Exception e) {
            return error(e);
        }
    }
    @ApiOperation(value = "查询合同技术参数", notes = "查询合同技术参数")
    @RequestMapping(value = "{contractSn}", method = RequestMethod.GET)
    public WebResult queryList(@PathVariable String contractSn){
        try {
            var result =  additionalMoneyservice.queryListByContractSn(contractSn);
            return  success("查询成功",result);
        } catch (Exception e) {
            return error(e);
        }
    }
    @ApiOperation(value = "查询所有技术参数", notes = "查询所有技术参数")
    @RequestMapping(value = "", method = RequestMethod.GET)
    public WebResult queryitem(){
       var result = dtSvc.findDictItemByCode("productBuildWay");
        result.addAll(dtSvc.findDictItemByCode("imperviousLevel"));
        result.addAll(dtSvc.findDictItemByCode("technicTag"));
        return success("查询成功",result);
    }
}
